/**
 * File: InputStreamProvider.java
 * Created by: mhaimel
 * Created on: Aug 1, 2011
 * CVS:  $Id: InputStreamProvider.java 1.0 Aug 1, 2011 3:59:59 PM mhaimel Exp $
 */
package uk.ac.ebi.curtain.storage.sequence;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author mhaimel
 *
 */
public class InputStreamProvider implements StreamProvider<InputStream> {
	
	private final File file;

	public InputStreamProvider(File file) {
		this.file = file;
	}

	public InputStreamProvider(String file) {
		this(new File(file));
	}

	@Override
	public InputStream openAndGetStream() throws IOException {
		if(!file.exists()){
			throw new FileNotFoundException("File does not exist: "+getName());
		}
		if(file.length() == 0){
			throw new FileNotFoundException("File is empty: " + getName());
		}
		return new FileInputStream(file);
	}

	@Override
	public String getName() {
		return this.file.getAbsolutePath();
	}
}
